<template>
  <div>
    <div style="margin-bottom: 30px">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }"><span style="font-size: 20px">首页</span></el-breadcrumb-item>
        <el-breadcrumb-item><span style="font-size: 20px">个人信息</span></el-breadcrumb-item>
      </el-breadcrumb>
    </div>
  <el-card style="width: 500px;">
    <el-form label-width="120" :model="user">
      <el-form-item label="工号/学号">
        <el-input v-model="user.codeName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="user.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-select v-model="user.sex" filterable clearable placeholder="请选择">
          <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.value"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="user.phone" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  </div>
</template>

<script>
	import {user_update} from '../axios/api/userApi.js'
	
export default {
  name: "Person",
  data(){
    return{
      form:{},
      user:{},
      //通过后台把用户的信息传过来

      options: [{
        id: '1',
        value: '男'
      }, {
        id: '2',
        value: '女'
      }],
      value: ''
    }
  },
  created() {
	  this.user = JSON.parse(localStorage.getItem('user'))
   //  this.request.get("/user/username/" + this.user.username).then(res =>{
   //    if(res.code === '200'){
   //      this.form = res.data
   //    }
   //  })
  },
  methods:{
    save(){
      const data = this.user
	  //如果为学生修改个人信息则访问学生，否则为教师
	  user_update(data).then(res=>{
		  localStorage.setItem('user', JSON.stringify(data))
	  })
    },
  }
}
</script>

<style scoped>

</style>